# Updated by Wei on 2014/07/15
# plot the masterpiece

from __future__ import division
from operator import itemgetter, attrgetter
from struct import *
import gc
import math
import os
import random
import sys
import time
from sets import Set
from random import randint
import re
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d,Axes3D
import matplotlib as mpl

print "program begins..." 
fig = plt.figure()
ax = Axes3D(fig)

# x = np.array([1,2],np.int32)
x = np.array([[1,2],[1,2]])
y = np.array([2, 3])
n = np.max(x.shape)
X = np.vstack([np.ones(n), x]).T
a = np.linalg.lstsq(X, y)[0]
m0 = a[0]
m1 = a[1]
c = a[2]
print a
print m0
print m1
print c

plt.plot(x[0], x[1], y, 'o', label='Original data', markersize=10)
plt.plot(m0*x[0], m1*x[1], m0*x[0] + m1*x[1] + c,'r', label='Fitted line')

'''
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
ax.plot(x, y, z, label='parametric curve')
'''

ax.legend()
plt.show()
exit(1)

mpl.rcParams['legend.fontsize'] = 10

fig = plt.figure()
ax = fig.gca(projection='3d')
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
ax.plot(x, y, z, label='parametric curve')
ax.legend()

plt.show()
exit(1)

x = np.array([1,2],np.int32)
# x = np.array([[1,2],[1,2]],np.int32)
y = np.array([2, 3])
n = np.max(x.shape)
X = np.vstack([np.ones(n), x]).T
a = np.linalg.lstsq(X, y)[0]
print a
m = a[0]
c = a[1]

plt.plot(x, y, 'o', label='Original data', markersize=10)
plt.plot(x, m*x + c, 'r', label='Fitted line')
plt.legend()
plt.show()

exit(1)

xi = np.array([[1,2],[1,2]],np.int32)
A = np.array([ xi, np.ones(2)])

# linearly generated sequence
yi = [1, 2]
weightsSet1 = np.linalg.lstsq(A.T,yi)[0] # obtaining the parameters

print "regression:"
print "m1:",weightsSet1[0],"c1:",weightsSet1[1]
print "prediction"
'''
for target_quality in TARGET_QUALITIES:
    if target_quality >= x1 and target_quality < x2:
        target_indexSizeKept = target_quality * weightsSet1[0] + weightsSet1[1]
        target_queryProcessingCost1 = target_quality * weightsSet2[0] + weightsSet2[1]
        target_queryProcessingCost2 = target_quality * weightsSet3[0] + weightsSet3[1]
        outputFileLine = str(target_quality) + " " + str(target_indexSizeKept) + " " + str(target_queryProcessingCost1) + " " + str(target_queryProcessingCost2) + " " + str(methodNameList[methodIdentifier]) + " " + str(i)
        print outputFileLine
        outputFileHandler.write(outputFileLine + "\n")
'''
print "program ends."